package org.stone.project.webIntegration.utils;

import javax.servlet.http.HttpServletRequest;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.ContentType;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * 客户端工具类
 * 
 * @author ruoyi
 */
public class ServletUtils
{
    /**
     * 获取request
     */
    public static HttpServletRequest getRequest()
    {
        return getRequestAttributes().getRequest();
    }

    public static ServletRequestAttributes getRequestAttributes()
    {
        RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
        return (ServletRequestAttributes) attributes;
    }

    /**
     * 是否可能含有二进制
     * @return
     */
    public static boolean probHasFileContentType(String contentType){
        if (ObjectUtil.isNotEmpty(contentType)){
            String lowerCase = contentType.toLowerCase().split(";")[0];
            if (lowerCase.indexOf(ContentType.MULTIPART.getValue()) >= 0 || lowerCase.indexOf(ContentType.FORM_URLENCODED.getValue()) >= 0 ||  lowerCase.indexOf(ContentType.OCTET_STREAM.getValue()) >= 0 || lowerCase.indexOf(ContentType.EVENT_STREAM.getValue()) >= 0)
                return false;
        }
        return true;
    }
}
